package com.fenghongzhang.day013.mvp.model;

import com.fenghongzhang.day013.common.Api;
import com.fenghongzhang.day013.mvp.contract.MeiziContract;
import com.fenghongzhang.lib.mvp.model.BaseModel;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class MeiziModel extends BaseModel implements MeiziContract.IMeiZiModel {

    //请求数据
    @Override
    public void getMeiziData(Observer observer) {
        //retrofit和rxjava结合 -> okhttp
        new Retrofit.Builder()
                .client(new OkHttpClient.Builder().addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)).build())
                .baseUrl("https://gank.io/")
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build()
                .create(Api.class)
                .getMeizi("Girl","Girl","1","10")
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }
}
